<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2019/4/22
 * Time: 17:45
 */
namespace Modules\Admin\Main\Controllers;
use App\Models\SmsSendPlan;
use Illuminate\Http\Request;
use Modules\Api\Controllers\Controller;

class SmsController extends Controller
{
    public function search(Request $request){
        return view('main::sms_message', \Request::all());
    }

    public function apiSearch(Request $request){
        $data = [];
        $limit  = $request->input('limit', 10);
        $offset = $request->input('offset', 0);
        $query = SmsSendPlan::query();
        $data['count'] = $query->count();
        $res = $query->take($limit)->skip($offset)->orderBy('id', 'desc')->get();
        $data['data'] = [];
        foreach ($res as $item) {
            $_item = $item->toArray();

            $data['data'][] = $_item;
        }
        return success($data);
    }


    public function add(Request $request)
    {
        $templetId = $request->input('templet_id');
        $object  = $request->input('object');
        $collect = $request->input('collect');
        $date1 = $request->input('date1');
        $date2 = $request->input('date2');

        $data = [
            'templet_id'=>$templetId,'object'=>$object,'mobile'=>$collect,'status'=>0,
            'send_date'=>$date1.' '.$date2
        ];
        SmsSendPlan::create($data);
        return success();
    }

    public function delete(Request $request)
    {
        $id = $request->input('id');
        $info = SmsSendPlan::find($id);
        $info->delete();
        return success();
    }
}